#include "../scene/3dvr.h"
#include "../scene/mainpage.h"

using namespace cocos2d;

CCScene* P3dvrLayer01::scene()
{
	CCScene *scene = CCScene::node();
	P3dvrLayer01 *layer = P3dvrLayer01::node();
	scene->addChild(layer);
	return scene;
}

bool P3dvrLayer01::init()
{
	if(!CCLayer::init() )
	{
		return false;
	}

	CCSize size = CCDirector::sharedDirector()->getWinSize();

	CCSprite* pSprite = CCSprite::spriteWithFile("bg_setting.jpg");
	pSprite->setPosition(ccp(size.width/2,size.height/2));
	this->addChild(pSprite,0);

	CCSpriteFrameCache::sharedSpriteFrameCache()->addSpriteFramesWithFile("setbtn.plist");
	CCSpriteFrameCache::sharedSpriteFrameCache()->addSpriteFramesWithFile("all3dvr.plist");

	CCSprite* sprite_3dvrtitle = CCSprite::spriteWithSpriteFrame(CCSpriteFrameCache::sharedSpriteFrameCache()->spriteFrameByName("title_3dvr.png")); 

	CCSprite* sprite_forest01 = CCSprite::spriteWithSpriteFrame(CCSpriteFrameCache::sharedSpriteFrameCache()->spriteFrameByName("forest01.png"));
	CCSprite* sprite_forest02 = CCSprite::spriteWithSpriteFrame(CCSpriteFrameCache::sharedSpriteFrameCache()->spriteFrameByName("forest02.png"));
	sprite_forest02->setPosition(ccp(3,-3));


	CCSprite* sprite_trackday01 = CCSprite::spriteWithSpriteFrame(CCSpriteFrameCache::sharedSpriteFrameCache()->spriteFrameByName("trackDay01.png"));
	CCSprite* sprite_trackday02 = CCSprite::spriteWithSpriteFrame(CCSpriteFrameCache::sharedSpriteFrameCache()->spriteFrameByName("trackDay02.png"));
	sprite_trackday02->setPosition(ccp(3,-3));

	CCSprite* sprite_seaisland01 = CCSprite::spriteWithSpriteFrame(CCSpriteFrameCache::sharedSpriteFrameCache()->spriteFrameByName("seaIsland01.png"));
	CCSprite* sprite_seaisland02 = CCSprite::spriteWithSpriteFrame(CCSpriteFrameCache::sharedSpriteFrameCache()->spriteFrameByName("seaIsland02.png"));
	sprite_seaisland02->setPosition(ccp(3,-3));

	CCSprite* sprite_tracknight01 = CCSprite::spriteWithSpriteFrame(CCSpriteFrameCache::sharedSpriteFrameCache()->spriteFrameByName("trackNight01.png"));
	CCSprite* sprite_tracknight02 = CCSprite::spriteWithSpriteFrame(CCSpriteFrameCache::sharedSpriteFrameCache()->spriteFrameByName("trackNight02.png"));
	sprite_tracknight02->setPosition(ccp(3,-3));


	CCSprite* sprite_home01 = CCSprite::spriteWithSpriteFrame(CCSpriteFrameCache::sharedSpriteFrameCache()->spriteFrameByName("btn_home.png"));
	CCSprite* sprite_home02 = CCSprite::spriteWithSpriteFrame(CCSpriteFrameCache::sharedSpriteFrameCache()->spriteFrameByName("btn_home.png"));
	sprite_home02->setPosition(ccp(3,-3));

	CCSprite* sprite_help01 = CCSprite::spriteWithSpriteFrame(CCSpriteFrameCache::sharedSpriteFrameCache()->spriteFrameByName("help01.png"));
	CCSprite* sprite_help02 = CCSprite::spriteWithSpriteFrame(CCSpriteFrameCache::sharedSpriteFrameCache()->spriteFrameByName("help02.png"));


	float sbw = size.width / 1024;
	float sbh = size.height / 768;

	sprite_3dvrtitle->setPosition(ccp((sbw*512.0f), size.height - (sbh *135.0f)));
	this->addChild(sprite_3dvrtitle,0);


	CCMenuItemSprite* item_forest = CCMenuItemSprite::itemFromNormalSprite(sprite_forest01,sprite_forest02,this,menu_selector(P3dvrLayer01::menuForestCallback));
	item_forest->setPosition(ccp((sbw*356.0f), size.height - (sbh *334.0f)));

	CCMenuItemSprite* item_trackday = CCMenuItemSprite::itemFromNormalSprite(sprite_trackday01,sprite_trackday02,this,menu_selector(P3dvrLayer01::menuTrackDayCallback));
	item_trackday->setPosition(ccp((sbw*670.0f), size.height - (sbh *334.0f)));

	CCMenuItemSprite* item_seaisland = CCMenuItemSprite::itemFromNormalSprite(sprite_seaisland01,sprite_seaisland02,this,menu_selector(P3dvrLayer01::menuSeaIslandCallback));
	item_seaisland->setPosition(ccp((sbw*356.0f), size.height - (sbh *480.0f)));

	CCMenuItemSprite* item_tracknight = CCMenuItemSprite::itemFromNormalSprite(sprite_tracknight01,sprite_tracknight02,this,menu_selector(P3dvrLayer01::menuTrackNightCallback));
	item_tracknight->setPosition(ccp((sbw*670.0f), size.height - (sbh *480.0f)));


	CCMenuItemSprite* item_home = CCMenuItemSprite::itemFromNormalSprite(sprite_home01,sprite_home02,this,menu_selector(P3dvrLayer01::menuHomeCallback));
	item_home->setPosition(ccp((sbw*960.0f), size.height - (sbh *700.0f)));

	CCMenuItemSprite* item_help = CCMenuItemSprite::itemFromNormalSprite(sprite_help01,sprite_help02,this,menu_selector(P3dvrLayer01::menuHelpCallback));
	item_help->setPosition(ccp((sbw*980.0f), size.height - (sbh *70.0f)));

	CCMenu* pmenu = CCMenu::menuWithItems(item_forest,item_trackday,item_seaisland,item_tracknight,item_home,item_help, NULL);
	pmenu->setPosition(CCPointZero);

	this->addChild(pmenu);

	return true;


}
//-------------------------------------------------------------------
void P3dvrLayer01::menuCloseCallback(CCObject* pSender)
{
    // "close" menu item clicked
    //CCDirector::sharedDirector()->end();
	

}
//-------------------------------------------------------------------
void P3dvrLayer01::menuForestCallback(cocos2d::CCObject *pSender)
{

}
//-------------------------------------------------------------------
void P3dvrLayer01::menuTrackDayCallback(cocos2d::CCObject *pSender)
{

}
//-------------------------------------------------------------------
void P3dvrLayer01::menuSeaIslandCallback(cocos2d::CCObject *pSender)
{

}
//-------------------------------------------------------------------
void P3dvrLayer01::menuTrackNightCallback(cocos2d::CCObject *pSender)
{

}
//-------------------------------------------------------------------
void P3dvrLayer01::menuHomeCallback(cocos2d::CCObject *pSender)
{
	CCScene* s = MainPageLayer01::scene();
	CCScene* pScene = CCTransitionCrossFade::transitionWithDuration(0.5f, s);
    CCDirector::sharedDirector()->replaceScene(pScene);
}
//-------------------------------------------------------------------
void P3dvrLayer01::menuHelpCallback(cocos2d::CCObject *pSender)
{

}